#version 110

uniform mat4 modelViewProj;
uniform mat4 modelView;
uniform mat4 model;
uniform mat3 normalMat;
uniform vec3 lightPos; // light pos in eye space

attribute vec3 pos;
attribute vec3 norm;

varying vec3 normVarying;
varying vec3 lightDirVarying;
varying vec3 viewDirVarying;

void main()
{
    vec4 eyeVertex = modelView * vec4(pos, 1); // pos in eye space
    eyeVertex /= eyeVertex.w;

    normVarying = normalMat * norm;
    lightDirVarying = eyeVertex.xyz - lightPos;

    //TODO: I think we prefer to calc smooth normals on CPU (better performance for old GPU's?)
    // smooth normals
    //normVarying = -vec3(model * normalize(vec4(pos, 1))); // pos in world space
    //lightDirVarying = eyeVertex.xyz - lightPos;

    viewDirVarying = -eyeVertex.xyz;
    gl_Position = modelViewProj * vec4(pos, 1); //gl_Position = mvpMatrix * vertex;
}
